<template>
  <div class="viewContain">
   11
  </div>
</template>

<script>
import { getDeliveryPrice, provinceList, deliveryList, addPriceInfo, updatePriceInfo, deleteDeliveryPrice, findByConditonDelivery } from '@/api/index'
import Dialog from '@/components/dailog/index.vue'
import pagination from '@/components/pagination/index.vue'

export default {
  components: {
    Dialog, pagination
  },
  data() {
    return {
      totalCount: 0,
      loading: false,
      options: [],
      addressList: [],
      deliveryListData: [],
      listQuery: {
        pageNum: 1,
        pageSize: 10,
        area: '',
        deliveryName: ''
      },
      tableData: [],
      rules: {
        firstWeight: [
          { required: true, message: '请输入面单价格', trigger: 'blur' }
        ],
        secondWeight: [
          { required: true, message: '请输入续重价格', trigger: 'change' }
        ],
        secondWeightOne: [
          { required: true, message: '请输入续重价格', trigger: 'change' }
          // { required: !!this.isShowSecondOne, message: '请输入续重价格', trigger: 'change' }
        ],
        deliveryType: [
          { required: true, message: '请选择快递种类', trigger: 'change' }
        ],
        areaCode: [
          { required: true, message: '请选择发货区域', trigger: 'change' }
        ]
      },
      rules1: {},
      formData: {
        area: '',
        areaCode: '',
        deliveryName: '',
        deliveryType: '',
        firstWeight: '',
        id: '',
        secondWeight: '',
        secondWeightOne: ''
      },
      dailog: {
        // height: '',
        title: '快递新增',
        visible: false,
        visibleAssign: false,
        width: ''
      },
      isShowSecondOne: true
    }
  },
  mounted() {
    this.getList()
    this.getAddressList()
    this.getDeliveryList()
  },
  methods: {
    // 筛选快递类型
    selectDeliveryType(e) {
      // console.log(e)
      // if (e === '59a24773-c16f-4c82-9665-2ebc2c1374c1') {
      //   this.isShowSecondOne = true
      // } else {
      //   this.isShowSecondOne = false
      // }
    },
    // 快递价格列表
    getList() {
      this.loading = true
      getDeliveryPrice(this.listQuery).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.tableData = res.data.list
          this.totalCount = res.data.total
          this.loading = false
        } else {
          this.loading = false
        }
      })
    },
    // 查询
    handleSearch() {
      // this.getList()
      findByConditonDelivery(this.listQuery).then(res => {
        if (res.code === 200) {
          this.tableData = res.data.list
          this.totalCount = res.data.total
          this.loading = false
        } else {
          this.loading = false
        }
      })
    },
    // 省份信息
    getAddressList() {
      const params = { pageNum: 1, pageSize: 100 }
      provinceList(params).then(res => {
        if (res.code === 200) {
          this.addressList = res.data.list
        }
      })
    },
    // 快递种类
    getDeliveryList() {
      deliveryList().then(res => {
        if (res.code === 200) {
          this.deliveryListData = res.data.list
          console.log('this.deliveryListData====', this.deliveryListData)
        }
      })
    },

    // 新增
    handleAdd() {
      // alert('开发中,敬请期待~')
      this.formData = {
        area: '',
        areaCode: '',
        deliveryName: '',
        deliveryType: '',
        firstWeight: '',
        id: '',
        secondWeight: ''
      }
      this.dailog.visible = true
      this.dailog.title = '新增'
    },
    // 删除
    handleDelete(id) {
      // alert('开发中,敬请期待~')
      this.$confirm('是否删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // const params = { ids: id }
        const ids = id
        deleteDeliveryPrice({}, ids).then(res => {
          console.log('res====删除结果', res)
          if (res.code === 200) {
            this.$message({
              type: 'success',
              message: res.message
            })
            this.getList()
          }
        })
      })
    },
    handleReload() {
      // alert('开发中,敬请期待~')
      this.listQuery.pageNum = 1
      this.listQuery.pageSize = 10
      this.listQuery.area = ''
      this.listQuery.deliveryName = ''
      this.getList()
    },
    handleEdit(row) {
      this.dailog.visible = true
      this.dailog.title = '编辑'
      this.$nextTick(() => {
        this.formData = JSON.parse(JSON.stringify(row))
        console.log('this.formData开始编辑', this.formData)
      })
    },
    handleConfirm() {
      this.$refs['formData'].validate((valid) => {
        if (valid) {
          this.dailog.visible = false
          console.log('编辑===this.formData', this.formData)
          // this.formData.firstWeight = Number(this.formData.firstWeight)
          // this.formData.secondWeight = Number(this.formData.secondWeight)
          if (this.dailog.title === '新增') {
            addPriceInfo(this.formData).then(res => {
              if (res.code === 200) {
                this.getList()
                this.$message({ type: 'success', message: '新增成功' })
                this.$refs['formData'].resetFields()
              }
            })
          } else {
            updatePriceInfo(this.formData).then(res => {
              if (res.code === 200) {
                this.getList()
                this.listQuery.pageNum = 1
                this.listQuery.pageSize = 10
                this.listQuery.area = ''
                this.listQuery.deliveryName = ''
                this.$message({ type: 'success', message: '修改成功' })
              }
            })
          }
        }
      })
    },
    handleCloseDialog() {
      this.dailog.visible = false
      console.log(123)
    }
  }
}
</script>

<style scoped>

</style>

